package com.st.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.st.base.BaseResult;
import com.st.vo.BannerListVo;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;

import java.util.ArrayList;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import com.st.pojo.Banner;
import com.st.dao.BannerMapper;
import com.st.service.BannerService;
@Service
public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner> implements BannerService{

    @Resource
    private BannerMapper bannerMapper;
    @Override
    public int batchInsert(List<Banner> list) {
        return baseMapper.batchInsert(list);
    }

    public List<BannerListVo> getList(){
        //1.获取基础数据
        List<Banner> bannerList = bannerMapper.selectList(null);

        List<BannerListVo> bannerListVos = new ArrayList<>();

        //2.过滤返回的数据
        for (Banner banner : bannerList) {
            BannerListVo bannerListVo = new BannerListVo(banner.getImgUrl(),banner.getForwordUrl());
            bannerListVos.add(bannerListVo);
        }
        //3.返回
        return bannerListVos;
    }

    @Override
    public List<BannerListVo> getPageList(Integer pageNumber, Integer pageSize) {
        //1.创建分页对象
        Page<Banner> page = new Page<>();
        page.setSize(pageSize);
        page.setCurrent(pageNumber);
        //2.按照分页信息查询分页数据
        List<Banner> banners = bannerMapper.selectList(page, null);

        //3.过滤数据
        List<BannerListVo> bannerListVos = new ArrayList<>();

        for (Banner banner : banners) {
            BannerListVo bannerListVo = new BannerListVo(banner.getImgUrl(),banner.getForwordUrl());
            bannerListVos.add(bannerListVo);
        }
        return bannerListVos;
    }
}
